<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>猜数字小游戏</title>
</head>
<body>
    <div>请输入要猜的数字</div>
    <input type="text">
    <button>提交</button>
    
    <div class="result">

    </div>

    <script>
        //1.生成一个1-100的随机整数
        let toGuess = parseInt(100 * Math.random() + 1)
        console.log(toGuess);

        //2. 进行猜数字操作
        let input = document.querySelector('input');
        let resultDiv = document.querySelector('.result');
        let button = document.querySelector('button');
        button.onclick = function() {
            //3.取出输入框中的内容
            if(input.value == '') {
                //用户啥都没输入，直接返回
            }
            //input.value 是获取到内容 是字符串
            let inputNum = parseInt(input.value);
            //4.判断大小
            if(inputNum < toGuess) {
                //猜小了
                resultDiv.innerHTML = '猜小了';
            } else if(inputNum > toGuess) {
                //猜大了
                resultDiv.innerHTML = '猜大了';
            } else {
                //猜对了
                resultDiv.innerHTML = '猜对了';
            }

        }

    </script>

</body>
</html>